import { showMessage } from '@/utils/messageUtils.js'

// 再次封装 request
const simpleRequest = async (fn, params = null, onSuccess = () => {
}, successMessage = null, errorMessage = null) => {
	const { message, data, success } = await fn(params)

	if (success) {
		showMessage(successMessage || data.message, data.code >= 100 && data.code < 300 ? 'success' : 'error')
		onSuccess(data)
	} else showMessage(errorMessage || data?.message || message, 'error')
}

export default simpleRequest